package com.example.com.skills_utf8;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;

import android.app.ExpandableListActivity;
import android.app.Fragment;
import android.app.FragmentTransaction;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.SimpleExpandableListAdapter;

public class ExpandableListView32Activity extends ExpandableListActivity{

	ExpandableListView32Activity activity = this;
	
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_expandable_listview32);
		
		
		/**
		 * 有关数据的说明： 当一级条目有多个的的时候，需要使用容器把所有的以及条目整合到一起。
		 */

		// 创建数据容器存放一级条目----------------------------------
		ArrayList<Map<String, String>> items = new ArrayList<Map<String, String>>();
		// 创建两个一级条目
		Map<String, String> item1 = new HashMap<String, String>();
		Map<String, String> item2 = new HashMap<String, String>();
		// 为一级条目添加数据
		item1.put("items", "同學");
		item2.put("items", "朋友");
		// 绑定一级条目
		items.add(item1);
		items.add(item2);
		
		

		// -------------第一个二级条目的内容
		ArrayList<Map<String, String>> subitem1 = new ArrayList<Map<String, String>>();
		Map<String, String> subitem1Date1 = new HashMap<String, String>();
		Map<String, String> subitem1Date2 = new HashMap<String, String>();
		subitem1Date1.put("subitems", "张飞");
		subitem1Date2.put("subitems", "关羽");
		subitem1.add(subitem1Date1);
		subitem1.add(subitem1Date2);

		// -------------第二个二级条目的内容
		ArrayList<Map<String, String>> subitem2 = new ArrayList<Map<String, String>>();
		Map<String, String> subitem2Date1 = new HashMap<String, String>();
		Map<String, String> subitem2Date2 = new HashMap<String, String>();
		subitem2Date1.put("subitems", "张龙");
		subitem2Date2.put("subitems", "赵虎");
		subitem2.add(subitem2Date1);
		subitem2.add(subitem2Date2);
		
		
		// 创建容器存放二级条目----------------------------------------
		ArrayList<ArrayList<Map<String, String>>> subitems = new ArrayList<ArrayList<Map<String, String>>>();
		// 整合二级条目
		subitems.add(subitem1);
		subitems.add(subitem2);
		
		
		SimpleExpandableListAdapter simpleExpandableListAdapter = new SimpleExpandableListAdapter(
				this, items, R.layout.item_32, new String[] { "items" },
				new int[] { R.id.item_TextView }, subitems, R.layout.sub_item_32,
				new String[] { "subitems" },
				new int[] { R.id.sub_item_TextView });
		
		
		setListAdapter(simpleExpandableListAdapter);
		
		///////////////////////////////////////////////////////////////////////////
		// 使用fragment
		
		
		final RelativeLayout layout_content = (RelativeLayout)findViewById(R.id.layout_content);
		Button btn_fragment1 = (Button)findViewById(R.id.btn_fragment1);
		btn_fragment1.setOnClickListener( new OnClickListener() {
			
			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
			
				layout_content.removeAllViews();
				
				
				Fragment newFragment = new fragment32();
		        FragmentTransaction ft = getFragmentManager().beginTransaction();
		        ft.replace(R.id.layout_frame, newFragment).commit();
				
				
			}
		});
		
		Button btn_fragment2 = (Button)findViewById(R.id.btn_fragment2);
		btn_fragment2.setOnClickListener( new OnClickListener() {
			
			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
			
				layout_content.removeAllViews();
				
				
				Fragment newFragment = new fragment32_1();
		        FragmentTransaction ft = getFragmentManager().beginTransaction();
		        ft.replace(R.id.layout_frame, newFragment).commit();
				
				
			}
		});
		
        
        
		
	}
	
	
	
	
}
